package org.jzs.mybaseapp.common.retorift;


import org.jzs.mybaseapp.Applications;

import rx.Subscriber;

/**
 * Created by Jzs on 2017/8/8 0008.
 */

class DownSubscriber<ResponseBody> extends Subscriber<ResponseBody> {
    DownloadCallBack callBack;

    public DownSubscriber(DownloadCallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public void onStart() {
        super.onStart();
        if (callBack != null) {
            callBack.onStart();
        }
    }

    @Override
    public void onCompleted() {
        if (callBack != null) {
            callBack.onCompleted();
        }
    }

    @Override
    public void onError(Throwable e) {
        if (callBack != null) {
            callBack.onError(e);
        }
    }

    @Override
    public void onNext(ResponseBody responseBody) {
        DownLoadManager.getInstance(callBack).writeResponseBodyToDisk(Applications.context(), (okhttp3.ResponseBody) responseBody);

    }
}
